
 <!DOCTYPE HTML>
<html lang="ch">
<head>
  <meta charset="UTF-8">
  
    <title>假币问题 | Yuan</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=no">
    
    <meta name="author" content="Luo Yuan">
    

    
    <meta name="description" content="有一堆硬币，里面有一个假币，如何通过称重的方式尽快找出这个假币呢。">
<meta property="og:type" content="article">
<meta property="og:title" content="假币问题">
<meta property="og:url" content="http://luoyuan800.github.io/2017/01/03/coin-java/index.html">
<meta property="og:site_name" content="Yuan">
<meta property="og:description" content="有一堆硬币，里面有一个假币，如何通过称重的方式尽快找出这个假币呢。">
<meta property="og:locale">
<meta property="article:published_time" content="2017-01-03T08:19:43.000Z">
<meta property="article:modified_time" content="2021-04-22T08:04:09.599Z">
<meta property="article:author" content="Luo Yuan">
<meta name="twitter:card" content="summary">

    
    <link rel="alternative" href="/atom.xml" title="Yuan" type="application/atom+xml">
    
    
    <link rel="icon" href="/img/favicon.ico">
    
    
    <link rel="apple-touch-icon" href="/img/jacman.jpg">
    <link rel="apple-touch-icon-precomposed" href="/img/jacman.jpg">
    
    
<link rel="stylesheet" href="/css/style.css">
<link rel="stylesheet" href="/%02.css">
<link rel="stylesheet" href="/.css">

<meta name="generator" content="Hexo 5.4.0"></head>

  <body>
    <header>
      
<div>
		
			<div id="imglogo">
				<a href="/"><img src="/img/logo.png" alt="Yuan" title="Yuan"/></a>
			</div>
			
			<div id="textlogo">
				<h1 class="site-name"><a href="/" title="Yuan">Yuan</a></h1>
				<h2 class="blog-motto">一点一滴，积累技术</h2>
			</div>
			<div class="navbar"><a class="navbutton navmobile" href="#" title="Menu">
			</a></div>
			<nav class="animated">
				<ul>
					<ul>
					 
						<li><a href="/">Home</a></li>
					
						<li><a href="/archives">Archives</a></li>
					
						<li><a href="/about">About</a></li>
					
					<li>
 					
					<form class="search" action="//google.com/search" method="get" accept-charset="utf-8">
						<label>Search</label>
						<input type="search" id="search" name="q" autocomplete="off" maxlength="20" placeholder="Search" />
						<input type="hidden" name="q" value="site:luoyuan800.github.io">
					</form>
					
					</li>
				</ul>
			</nav>			
</div>
    </header>
    <div id="container">
      <div id="main" class="post" itemscope itemprop="blogPost">
  
	<article itemprop="articleBody"> 
		<header class="article-info clearfix">
  <h1 itemprop="name">
    
      <a href="/2017/01/03/coin-java/" title="假币问题" itemprop="url">假币问题</a>
  </h1>
  <p class="article-author">By
       
		<a href="/about" title="Luo Yuan" target="_blank" itemprop="author">Luo Yuan</a>
		
  <p class="article-time">
    <time datetime="2017-01-03T08:19:43.000Z" itemprop="datePublished"> Published 2017-01-03</time>
    
  </p>
</header>
	<div class="article-content">
		
		<div id="toc" class="toc-article">
			<strong class="toc-title">Contents</strong>
		
			<ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B7%B2%E7%BB%8F%E5%81%87%E5%B8%81%E8%B4%A8%E9%87%8F%E6%AF%94%E7%9C%9F%E5%B8%81%E8%BD%BB%EF%BC%88%E9%87%8D%EF%BC%89"><span class="toc-number">1.</span> <span class="toc-text">已经假币质量比真币轻（重）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%8D%E7%9F%A5%E9%81%93%E5%81%87%E5%B8%81%E6%98%AF%E6%AF%94%E8%BE%83%E8%BD%BB%E8%BF%98%E6%98%AF%E6%AF%94%E8%BE%83%E9%87%8D"><span class="toc-number">2.</span> <span class="toc-text">不知道假币是比较轻还是比较重</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%86%E4%B8%A4%E5%A0%86"><span class="toc-number">2.1.</span> <span class="toc-text">分两堆</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%86%E4%B8%89%E5%A0%86"><span class="toc-number">2.2.</span> <span class="toc-text">分三堆</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BF%AD%E4%BB%A3%E7%AE%97%E6%B3%95"><span class="toc-number">2.3.</span> <span class="toc-text">迭代算法</span></a></li></ol></li></ol>
		
		</div>
		
		<p>有一堆硬币，里面有一个假币，如何通过称重的方式尽快找出这个假币呢。<span id="more"></span></p>
<p>这个问题有两种不同难度的版本</p>
<h2 id="已经假币质量比真币轻（重）"><a href="#已经假币质量比真币轻（重）" class="headerlink" title="已经假币质量比真币轻（重）"></a>已经假币质量比真币轻（重）</h2><p>常规的解题思路是将硬币分成两队，然后称重，那么假币就在较轻的那一堆，接下来只要继续对较轻的那一堆再继续分成两堆进行称重，知道找出假币。当然，有一个需要额处理的情况就是如果硬币数量是奇数的话，分成两堆后，会多出一个硬币，如果分出的两堆重量，一样，那么多出的那个硬币就是假币了。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">public int findByDivide2WhenForgeLighter(Coin[] coins) &#123;</span><br><span class="line">    if (coins.length &#x3D;&#x3D; 1) &#123;</span><br><span class="line">        return 0;</span><br><span class="line">    &#125;</span><br><span class="line">    if (coins.length &#x3D;&#x3D; 0) &#123;</span><br><span class="line">        return -1;</span><br><span class="line">    &#125;</span><br><span class="line">    int divide &#x3D; divide2(coins.length);</span><br><span class="line">    int end &#x3D; coins.length - 1;</span><br><span class="line">    if (coins.length % 2 !&#x3D; 0) &#123;</span><br><span class="line">        end &#x3D; coins.length - 2;</span><br><span class="line">    &#125;</span><br><span class="line">    int total &#x3D; total(0, divide - 1, coins);&#x2F;&#x2F;total方法是对指定的硬币进行称重，当然在代码的实现里面就是将所有硬币的数量加起来，这里不再赘述</span><br><span class="line">    int total1 &#x3D; total(divide, end, coins);</span><br><span class="line">    if (total &lt; total1) &#123;</span><br><span class="line">        return findByDivide2WhenForgeLighter(Arrays.copyOfRange(coins, 0, divide));&#x2F;&#x2F;递归</span><br><span class="line">    &#125; else if (total &gt; total1) &#123;</span><br><span class="line">        return findByDivide2WhenForgeLighter(Arrays.copyOfRange(coins, divide, end));&#x2F;&#x2F;递归</span><br><span class="line">    &#125; else if (coins.length % 2 !&#x3D; 0) &#123;</span><br><span class="line">    &#x2F;&#x2F;如果硬币的个数是奇数的话，那么分堆后肯定会多出来一个硬币，如果分出来的两堆硬币重量一样，这个多出来的就肯定是假币</span><br><span class="line">        return coins.length - 1;</span><br><span class="line">    &#125; else &#123;</span><br><span class="line">    &#x2F;&#x2F;如果</span><br><span class="line">        return -1;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>其中分堆的方法可以定义成如下</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">private int divide2(int length) &#123;</span><br><span class="line">    if (length % 2 &#x3D;&#x3D; 0) &#123;</span><br><span class="line">    &#x2F;&#x2F;如果是偶数的话直接分成等量的两堆</span><br><span class="line">        return length &#x2F; 2;</span><br><span class="line">    &#125; else &#123;&#x2F;&#x2F;如果是奇数的话，取掉最后一个硬币后再进行分（其实就是分成了三堆，其中一堆只有一个）</span><br><span class="line">        return (length - 1) &#x2F; 2;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>当然我们还可以使用另外一种进阶的方式，就是分成三堆，分成三堆可以实现，称重一次排除掉两堆，平均的情况下可以实现每次称重后都将硬币的规模缩减为原来的1/3。这样可以大幅度的减少称重的次数，特别是硬币比较多的时候。代码实现如下。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">public int findByDivide3WhenFakeLighter(Coin[] conins) &#123;</span><br><span class="line">    if (conins.length &lt;&#x3D; 1) &#123;</span><br><span class="line">        return conins.length - 1;</span><br><span class="line">    &#125;</span><br><span class="line">    int[] divides &#x3D; divide3(conins.length);</span><br><span class="line">    int total1 &#x3D; total(0, divides[0] - 1, conins);</span><br><span class="line">    int total2 &#x3D; total(divides[0], divides[1] - 1, conins);</span><br><span class="line">    if (total1 &lt; total2) &#123;&#x2F;&#x2F;假币在第一堆（比较轻）</span><br><span class="line">        return findByDivide3WhenFakeLighter(Arrays.copyOfRange(conins, 0, divides[0]));</span><br><span class="line">    &#125; else if (total1 &gt; total2) &#123;&#x2F;&#x2F;假币在第二堆</span><br><span class="line">        return findByDivide3WhenFakeLighter(Arrays.copyOfRange(conins, divides[0], divides[1]));</span><br><span class="line">    &#125; else &#123;&#x2F;&#x2F;假币在第三堆</span><br><span class="line">        return findByDivide3WhenFakeLighter(Arrays.copyOfRange(conins, divides[1], conins.length));</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>其中分堆的算法实现如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F;返回的数组[0]是第一堆的结束位置，[1]是第二堆的结束位置</span><br><span class="line">&#x2F;&#x2F;特别处理当硬币个数只有两个的时候，只分成两堆</span><br><span class="line">    private int[] divide3(int length) &#123;</span><br><span class="line">        if (length &lt; 3) &#123;</span><br><span class="line">            return new int[]&#123;1, 2&#125;;</span><br><span class="line">        &#125;</span><br><span class="line">        int size &#x3D; length &#x2F; 3;</span><br><span class="line">        return new int[]&#123;size, 2 * size&#125;;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>
<p>上面提到的都是用减量递归的方式查找假币，下面尝试使用迭代的算法来实现一个分两堆的代码（分成三堆的实现模式差不多，不再赘述）。算法重只需要根据重量来改变指示剩余硬币的数量，基本的实现基础是剩下的硬币在代码中使用的存储是连续的。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">public int findByDivide2WhenForgeLighterIteration(Coin[] coins) &#123;</span><br><span class="line">    int newStart &#x3D; 0, newEnd &#x3D; coins.length -1;</span><br><span class="line">    &#x2F;&#x2F;两个指针之间的硬币就是剩余的硬币</span><br><span class="line">    while (newStart !&#x3D; newEnd) &#123;</span><br><span class="line">        int divide &#x3D; divide2(newEnd - newStart + 1);</span><br><span class="line">        int total1 &#x3D; total(newStart, newStart + divide, coins);</span><br><span class="line">        int total2 &#x3D; total(newStart + divide, newEnd, coins);</span><br><span class="line">        if(total1 &#x3D;&#x3D; total2)&#123;</span><br><span class="line">            return -1;</span><br><span class="line">        &#125;else if(total1 &gt; total2)&#123;</span><br><span class="line">        &#x2F;&#x2F;将第一个指针往后移动到划分的位置</span><br><span class="line">            newStart +&#x3D; divide;</span><br><span class="line">        &#125;else&#123;</span><br><span class="line">        &#x2F;&#x2F;将第二个指针往前移动</span><br><span class="line">            newEnd &#x3D; newStart + divide;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    return newStart;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="不知道假币是比较轻还是比较重"><a href="#不知道假币是比较轻还是比较重" class="headerlink" title="不知道假币是比较轻还是比较重"></a>不知道假币是比较轻还是比较重</h2><h3 id="分两堆"><a href="#分两堆" class="headerlink" title="分两堆"></a>分两堆</h3><p>如果不知道假币重量的情况下，分两堆的算法也是可以做到的：</p>
<ul>
<li>等分两堆</li>
<li>如果刚刚好分成两堆（偶数），随机选择一堆再进行等分，然后进行称重，如果一样的话，那么假币肯定在第二堆，就可以舍弃第一堆后再对余下的硬币重复以上步骤。</li>
<li>如果是奇数，对分好的两堆称重，如果相等，那么多出来的那个就是假币，否则随机选择一堆再进行等分，然后进行称重分析（参考前面步骤）。</li>
</ul>
<h3 id="分三堆"><a href="#分三堆" class="headerlink" title="分三堆"></a>分三堆</h3><p>在这里实现一个分三堆的算法（感觉逼格比较高）。实现思路是，分三堆，其中第一堆和第二堆个数相同，第三堆是分完两堆后余下的硬币。然后对第一堆和第二堆的重量进行比较，如果相同，那么假币肯定在第三堆，如果不相同，那么排除第三堆，混合第一堆和第二堆后重新分成三堆进行称重分析。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">public int findByDivide3WithUnknownWeight(Coin[] coins) &#123;</span><br><span class="line">    if (coins.length &lt;&#x3D; 1) &#123;</span><br><span class="line">        return coins.length - 1;</span><br><span class="line">    &#125;</span><br><span class="line">    int[] divides &#x3D; divide3(coins.length);</span><br><span class="line">    int total1 &#x3D; total(0, divides[0] - 1, coins);</span><br><span class="line">    int total2 &#x3D; total(divides[0], divides[1] - 1, coins);</span><br><span class="line">    if (total1 &#x3D;&#x3D; total2) &#123;</span><br><span class="line">        return findByDivide3WithUnknownWeight(Arrays.copyOfRange(coins, divides[1], coins.length));</span><br><span class="line">    &#125; else &#123;</span><br><span class="line">        return findByDivide3WithUnknownWeight(Arrays.copyOfRange(coins, 0, divides[1]));</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>分堆用到的算法和之前的一样，可以应付个数不是三的倍数时候的情况。<br>这个算法的效率其实可以通过挑战第一堆和第二堆硬币数量的个数来进一步优化。在此不再赘述。</p>
<h3 id="迭代算法"><a href="#迭代算法" class="headerlink" title="迭代算法"></a>迭代算法</h3><p>当然还是要弄个非递归的算法来炫耀一下技术滴（分三堆）：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">public int findByDivide3WithUnknownWeightIteration(Coin[] coins) &#123;</span><br><span class="line">    int start &#x3D; 0;</span><br><span class="line">    int end &#x3D; coins.length - 1;</span><br><span class="line">    while (start !&#x3D; end) &#123;</span><br><span class="line">        int[] divides &#x3D; divide3(end + 1 - start);</span><br><span class="line">        int total1 &#x3D; total(0, divides[0] - 1, coins);</span><br><span class="line">        int total2 &#x3D; total(divides[0], divides[1] - 1, coins);</span><br><span class="line">        if (total1 &#x3D;&#x3D; total2) &#123;</span><br><span class="line">        &#x2F;&#x2F;舍弃前面的（选择第三堆进行接下来的分析）</span><br><span class="line">            start &#x3D; divides[1];</span><br><span class="line">        &#125; else &#123;</span><br><span class="line">        &#x2F;&#x2F;排除第三堆里的硬币，并且将前两堆重新划分成三堆</span><br><span class="line">            end &#x3D; divides[1];</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    return start;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>  
	</div>
		<footer class="article-footer clearfix">
<div class="article-catetags">

<div class="article-categories">
  <span></span>
  <a class="article-category-link" href="/categories/%E7%BC%96%E7%A8%8B-Java/">编程-Java</a>
</div>


</div>



	<div class="article-share" id="share">
	
	  <div data-url="http://luoyuan800.github.io/2017/01/03/coin-java/" data-title="假币问题 | Yuan" data-tsina="" class="share clearfix">
	  </div>
	
	</div>


</footer>

   	       
	</article>
	
<nav class="article-nav clearfix">
 
 <div class="prev" >
 <a href="/2017/02/16/child-disease/" title="小儿常见病">
  <strong>上一篇：</strong><br/>
  <span>
  小儿常见病</span>
</a>
</div>


<div class="next">
<a href="/2017/01/03/fib-java/"  title="斐波那契数列">
 <strong>下一篇：</strong><br/> 
 <span>斐波那契数列
</span>
</a>
</div>

</nav>

	



</div>  
      <div class="openaside"><a class="navbutton" href="#" title="Show Sidebar"></a></div>

  <div id="toc" class="toc-aside">
  <strong class="toc-title">Contents</strong>
 
 <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B7%B2%E7%BB%8F%E5%81%87%E5%B8%81%E8%B4%A8%E9%87%8F%E6%AF%94%E7%9C%9F%E5%B8%81%E8%BD%BB%EF%BC%88%E9%87%8D%EF%BC%89"><span class="toc-number">1.</span> <span class="toc-text">已经假币质量比真币轻（重）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%8D%E7%9F%A5%E9%81%93%E5%81%87%E5%B8%81%E6%98%AF%E6%AF%94%E8%BE%83%E8%BD%BB%E8%BF%98%E6%98%AF%E6%AF%94%E8%BE%83%E9%87%8D"><span class="toc-number">2.</span> <span class="toc-text">不知道假币是比较轻还是比较重</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%86%E4%B8%A4%E5%A0%86"><span class="toc-number">2.1.</span> <span class="toc-text">分两堆</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%86%E4%B8%89%E5%A0%86"><span class="toc-number">2.2.</span> <span class="toc-text">分三堆</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BF%AD%E4%BB%A3%E7%AE%97%E6%B3%95"><span class="toc-number">2.3.</span> <span class="toc-text">迭代算法</span></a></li></ol></li></ol>
 
  </div>

<div id="asidepart">
<div class="closeaside"><a class="closebutton" href="#" title="Hide Sidebar"></a></div>
<aside class="clearfix">

  


  
<div class="categorieslist">
	<p class="asidetitle">Categories</p>
		<ul>
		
		  
			<li><a href="/categories/杂物-医学/" title="杂物-医学">杂物-医学<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/categories/编程-Java/" title="编程-Java">编程-Java<sup>13</sup></a></li>
		  
		
		  
			<li><a href="/categories/编程-Linux-Unix/" title="编程-Linux/Unix">编程-Linux/Unix<sup>4</sup></a></li>
		  
		
		  
			<li><a href="/categories/编程-工具/" title="编程-工具">编程-工具<sup>4</sup></a></li>
		  
		
		  
			<li><a href="/categories/编程-网络协议/" title="编程-网络协议">编程-网络协议<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/categories/网站-开发/" title="网站-开发">网站-开发<sup>2</sup></a></li>
		  
		
		</ul>
</div>


  

  <div class="linkslist">
  <p class="asidetitle">Links</p>
    <ul>
        
          <li>
            
            	<a href="https://coderq.com" target="_blank" title="一个面向程序员交流分享的新一代社区">码农圈</a>
            
          </li>
        
          <li>
            
            	<a href="http://wuchong.me" target="_blank" title="Jark&#39;s Blog">Jark&#39;s Blog</a>
            
          </li>
        
    </ul>
</div>

  


  <div class="rsspart">
	<a href="/atom.xml" target="_blank" title="rss">RSS</a>
</div>

  <div class="weiboshow">
  <p class="asidetitle">Weibo</p>
    <iframe width="100%" height="119" class="share_self"  frameborder="0" scrolling="no" src="http://widget.weibo.com/weiboshow/index.php?language=&width=0&height=119&fansRow=2&ptype=1&speed=0&skin=9&isTitle=1&noborder=1&isWeibo=0&isFans=0&uid=&verifier=&dpc=1"></iframe>
</div>


</aside>
</div>
    </div>
    <footer><div id="footer" >
	
	<div class="line">
		<span></span>
		<div class="author"></div>
	</div>
	
	
	<section class="info">
		<p> Hello ,I&#39;m Luo Yuan in Zhuhai. <br/>
			Here is my place for knowledge accumulation.</p>
	</section>
	 
	<div class="social-font" class="clearfix">
		
		
		
		
		
		
		
		
		
		
	</div>
			
		

		<p class="copyright">
		Powered by <a href="http://hexo.io" target="_blank" title="hexo">hexo</a> and Theme by <a href="https://github.com/wuchong/jacman" target="_blank" title="Jacman">Jacman</a> © 2021 
		
		<a href="/about" target="_blank" title="Luo Yuan">Luo Yuan</a>
		
		
		</p>
</div>
</footer>
    <script src="/js/jquery-2.0.3.min.js"></script>
<script src="/js/jquery.imagesloaded.min.js"></script>
<script src="/js/gallery.js"></script>
<script src="/js/jquery.qrcode-0.12.0.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){ 
  $('.navbar').click(function(){
    $('header nav').toggleClass('shownav');
  });
  var myWidth = 0;
  function getSize(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
  };
  var m = $('#main'),
      a = $('#asidepart'),
      c = $('.closeaside'),
      o = $('.openaside');
  c.click(function(){
    a.addClass('fadeOut').css('display', 'none');
    o.css('display', 'block').addClass('fadeIn');
    m.addClass('moveMain');
  });
  o.click(function(){
    o.css('display', 'none').removeClass('beforeFadeIn');
    a.css('display', 'block').removeClass('fadeOut').addClass('fadeIn');      
    m.removeClass('moveMain');
  });
  $(window).scroll(function(){
    o.css("top",Math.max(80,260-$(this).scrollTop()));
  });
  
  $(window).resize(function(){
    getSize(); 
    if (myWidth >= 1024) {
      $('header nav').removeClass('shownav');
    }else{
      m.removeClass('moveMain');
      a.css('display', 'block').removeClass('fadeOut');
      o.css('display', 'none');
      
      $('#toc.toc-aside').css('display', 'none');
        
    }
  });
});
</script>

<script type="text/javascript">
$(document).ready(function(){ 
  var ai = $('.article-content>iframe'),
      ae = $('.article-content>embed'),
      t  = $('#toc'),
      ta = $('#toc.toc-aside'),
      o  = $('.openaside'),
      c  = $('.closeaside');
  if(ai.length>0){
    ai.wrap('<div class="video-container" />');
  };
  if(ae.length>0){
   ae.wrap('<div class="video-container" />');
  };
  c.click(function(){
    ta.css('display', 'block').addClass('fadeIn');
  });
  o.click(function(){
    ta.css('display', 'none');
  });
  $(window).scroll(function(){
    ta.css("top",Math.max(140,320-$(this).scrollTop()));
  });
});
</script>


<script type="text/javascript">
$(document).ready(function(){ 
  var $this = $('.share'),
      url = $this.attr('data-url'),
      encodedUrl = encodeURIComponent(url),
      title = $this.attr('data-title'),
      tsina = $this.attr('data-tsina'),
      description = $this.attr('description');
  var html = [
  '<div class="hoverqrcode clearfix"></div>',
  '<a class="overlay" id="qrcode"></a>',
  '<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="article-share-facebook" target="_blank" title="Facebook"></a>',
  '<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="article-share-twitter" target="_blank" title="Twitter"></a>',
  '<a href="#qrcode" class="article-share-qrcode" title="微信"></a>',
  '<a href="http://widget.renren.com/dialog/share?resourceUrl=' + encodedUrl + '&srcUrl=' + encodedUrl + '&title=' + title +'" class="article-share-renren" target="_blank" title="人人"></a>',
  '<a href="http://service.weibo.com/share/share.php?title='+title+'&url='+encodedUrl +'&ralateUid='+ tsina +'&searchPic=true&style=number' +'" class="article-share-weibo" target="_blank" title="微博"></a>',
  '<span title="Share to"></span>'
  ].join('');
  $this.append(html);

  $('.hoverqrcode').hide();

  var myWidth = 0;
  function updatehoverqrcode(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
    var qrsize = myWidth > 1024 ? 200:100;
    var options = {render: 'image', size: qrsize, fill: '#2ca6cb', text: url, radius: 0.5, quiet: 1};
    var p = $('.article-share-qrcode').position();
    $('.hoverqrcode').empty().css('width', qrsize).css('height', qrsize)
                          .css('left', p.left-qrsize/2+20).css('top', p.top-qrsize-10)
                          .qrcode(options);
  };
  $(window).resize(function(){
    $('.hoverqrcode').hide();
  });
  $('.article-share-qrcode').click(function(){
    updatehoverqrcode();
    $('.hoverqrcode').toggle();
  });
  $('.article-share-qrcode').hover(function(){}, function(){
      $('.hoverqrcode').hide();
  });
});   
</script>











<link rel="stylesheet" href="/fancybox/jquery.fancybox.css" media="screen" type="text/css">
<script src="/fancybox/jquery.fancybox.pack.js"></script>
<script type="text/javascript">
$(document).ready(function(){ 
  $('.article-content').each(function(i){
    $(this).find('img').each(function(){
      if ($(this).parent().hasClass('fancybox')) return;
      var alt = this.alt;
      if (alt) $(this).after('<span class="caption">' + alt + '</span>');
      $(this).wrap('<a href="' + this.src + '" title="' + alt + '" class="fancybox"></a>');
    });
    $(this).find('.fancybox').each(function(){
      $(this).attr('rel', 'article' + i);
    });
  });
  if($.fancybox){
    $('.fancybox').fancybox();
  }
}); 
</script>



<!-- Analytics Begin -->



<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "//hm.baidu.com/hm.js?e6d1f421bbc9962127a50488f9ed37d1";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>



<!-- Analytics End -->

<!-- Totop Begin -->

	<div id="totop">
	<a title="Back to Top"><img src="/img/scrollup.png"/></a>
	</div>
	<script src="/js/totop.js"></script>

<!-- Totop End -->

<!-- MathJax Begin -->
<!-- mathjax config similar to math.stackexchange -->


<!-- MathJax End -->

<!-- Tiny_search Begin -->

<!-- Tiny_search End -->

  </body>
</html>
